using System;

namespace cs_4_Bank
{
    class CashCard
    {
        int balance;
        CreditCard c;
        public CashCard() { }
        public CashCard(int balance, CreditCard c)
        {
            this.balance = balance;
            this.c = c;
        }       
        public void CheckBalance()
        {
            if (c.checkDate())
            {
                int balance0 = balance;
                balance = balance - c.getPayBalance();
                if (balance >= 0)
                {
                    Console.WriteLine("您的储蓄卡初始余额为{0}，支付信用卡欠款{1}，现余额为{2}，还款成功",balance0,c.getPayBalance(),balance);
                }
                else
                {
                    Console.WriteLine("您的储蓄卡初始余额为{0}，信用卡欠款为{1}，余额不足，还款失败",balance0, c.getPayBalance());
                }
            }
            else if (!c.checkDate())
            {
                Console.WriteLine("未到还款日期，还款日期为{0}，不需要还款\n", c.getPayDate());
            }
        }
    }

    class CreditCard
    {
        int PayDate = 30;
        int PayBalance;
        int TodayDate;
        public CreditCard() { }
        string Today = Console.ReadLine();
        
        public CreditCard(int PayBalance, int TodayDate)
        {
            this.PayBalance = PayBalance;
            this.TodayDate = int.Parse(Today);
        }
        public int getPayDate()
        {
            return PayDate;
        }
        public int getPayBalance()
        {
            return PayBalance;
        }
        public bool checkDate()
        {
            if (TodayDate == PayDate)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }

    class Delegate
    {
        public delegate void MeDelegate();
        public event MeDelegate NotifyEventOne;
        public void Notify()
        {
            if (NotifyEventOne != null)
            {
                Console.WriteLine("触发事件:");
                NotifyEventOne();
            }
        }
    }

    class Program
    {       
        static void Main(string[] args)
        {
            Delegate objDelegate = new Delegate();
            Console.WriteLine("请输入今日日期:");
            CreditCard p = new CreditCard(6000, 30);
            CashCard cash1 = new CashCard(3000, p);
            CashCard cash2 = new CashCard(1000, p);
            CashCard cash3 = new CashCard(9000, p);
            Console.WriteLine("请选择你的储蓄卡:");
            string Card = Console.ReadLine();
            switch (Card)
            {
                case "cash1": objDelegate.NotifyEventOne += new Delegate.MeDelegate(cash1.CheckBalance); break;
                case "cash2": objDelegate.NotifyEventOne += new Delegate.MeDelegate(cash2.CheckBalance); break;
                case "cash3": objDelegate.NotifyEventOne += new Delegate.MeDelegate(cash3.CheckBalance); break;
            }
            objDelegate.Notify();
        }
    }
}

